﻿using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class SteelBarPileCap
    {
        public static void CreateCircleHatchList(Database db, ref Extents2d ext, Point2d Point, double radius,
  double width,double lmax, double space, double DiaX, double DiaY, out List<Point3d> ptList, eDirection eDir=eDirection.E_TOP, string layer = "H点筋")
        {
            ptList = new List<Point3d>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
         
                #region 
                int num = (int)(width / space);
                for (int i = 0; i < num; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    switch(eDir)
                    {
                        case eDirection.E_TOP:
                            ci.Center = Point.C3D(space * i + DiaX, DiaY);
                            if(space * i + DiaX> lmax)
                                ci.Center = Point.C3D(lmax-2, DiaY);
                            break;
                        case eDirection.E_BOTTOM:
                            ci.Center = Point.C3D(space * i + DiaX, -DiaY);
                            if (space * i + DiaX > lmax)
                                ci.Center = Point.C3D(lmax - 2, -DiaY);
                            break;
                        case eDirection.E_LEFT:
                            ci.Center = Point.C3D(-DiaX, space * i + DiaY);
                            if (space * i + DiaY > lmax)
                                ci.Center = Point.C3D(-DiaX, lmax - 2);
                            break;
                        case eDirection.E_RIGHT:
                            ci.Center = Point.C3D(DiaX, space * i + DiaY);
                            if (space * i + DiaY > lmax)
                                ci.Center = Point.C3D(DiaX, lmax - 2);
                            break;
                    }
                    ptList.Add(ci.Center);
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                }

                #endregion


                tr.Commit();
            }
        }
        public static void CreateCircleHatchListNew(Database db, ref Extents2d ext, Point2d Point, double radius,
double width, double lmax, double space, double DiaX, double DiaY, out List<Point3d> ptList, out List<double> spaceList, out string spaceStr, eDirection eDir = eDirection.E_TOP, string layer = "H点筋")
        {
            ptList = new List<Point3d>();
            spaceList = new List<double>();
            spaceStr = "";
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 
                int num = (int)(width / space);
                spaceStr = (num) + "×" + space ;
                for (int i = 0; i < num; i++)
                {
                    if(i< num-1)
                        spaceList.Add(space);
                    else
                        spaceList.Add(width-space*num);
                    //画圆
                    Circle ci = new Circle();
                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            ci.Center = Point.C3D(space * i + DiaX, DiaY);
                            if (space * i + DiaX > lmax)
                                ci.Center = Point.C3D(lmax - 2, DiaY);
                            break;
                        case eDirection.E_BOTTOM:
                            ci.Center = Point.C3D(space * i + DiaX, -DiaY);
                            if (space * i + DiaX > lmax)
                                ci.Center = Point.C3D(lmax - 2, -DiaY);
                            break;
                        case eDirection.E_LEFT:
                            ci.Center = Point.C3D(-DiaX, space * i + DiaY);
                            if (space * i + DiaY > lmax)
                                ci.Center = Point.C3D(-DiaX, lmax - 2);
                            break;
                        case eDirection.E_RIGHT:
                            ci.Center = Point.C3D(DiaX, space * i + DiaY);
                            if (space * i + DiaY > lmax)
                                ci.Center = Point.C3D(DiaX, lmax - 2);
                            break;
                    }
                    ptList.Add(ci.Center);
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateAvgCircleHatchList(Database db, ref Extents2d ext, Point2d Point, double radius,
double width, double lmax, double space, double DiaX, double DiaY, out List<Point3d> ptList, out List<double> spaceList, out string capString, eDirection eDir = eDirection.E_TOP,bool isBoth=true, string layer = "H点筋",bool isDrawing=true)
        {
            ptList = new List<Point3d>();
            spaceList = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 
                int num = (int)(width / space);
                double avg = Math.Round((width - space * (num-1)) * 0.5,1);
                if (avg >= space*0.4)
                {
                    num= num + 1;                   
                }
                capString= avg+"+"+ (num-2)+"×"+ space+"+"+avg;
                for (int i = 0; i <=num; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            if (i == 0)
                            {
                                if(isBoth)
                                   ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2)+avg + DiaX, DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg+space *(i-1) + DiaX, DiaY);
                            }
                            break;
                        case eDirection.E_BOTTOM:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, -DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, -DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2) + avg + DiaX, -DiaY);            
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg + space * (i - 1) + DiaX, -DiaY);
                            }
                            break;
                        case eDirection.E_LEFT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D( -DiaX, avg + DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-DiaX, avg + space * (i - 1)  +DiaY);
                            }
                            break;
                        case eDirection.E_RIGHT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D( DiaX, avg + DiaY);

                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(DiaX, avg + space * (i - 1) + DiaY);
                            }
                            break;
                    }
                    ptList.Add(ci.Center);
                    if(i>0)
                    {
                        if (i == 1 || i == num)
                            spaceList.Add(avg);
                        else
                            spaceList.Add(space);
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    if (isDrawing)
                    {
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));

                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt[layer];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateAvgCircleHatchListByCount(Database db, ref Extents2d ext, Point2d Point, double radius,
double width, double lmax, int num, double DiaX, double DiaY, out List<Point3d> ptList, out List<double> spaceList, out string capString, eDirection eDir = eDirection.E_TOP, bool isBoth = true, string layer = "H点筋")
        {
            ptList = new List<Point3d>();
            spaceList = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 
                double space =Math.Round( (width / num),1);
                double avg = Math.Round((width - space * (num - 2)) * 0.5, 1);
              
                capString = avg + "+" + (num - 2) + "×" + space + "+" + avg;
                if(avg==space)
                {
                    capString =  num + "×" + space ;
                }
                for (int i = 0; i <= num; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2) + avg + DiaX, DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg + space * (i - 1) + DiaX, DiaY);
                            }
                            break;
                        case eDirection.E_BOTTOM:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, -DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, -DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2) + avg + DiaX, -DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg + space * (i - 1) + DiaX, -DiaY);
                            }
                            break;
                        case eDirection.E_LEFT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(-DiaX, avg + DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-DiaX, avg + space * (i - 1) + DiaY);
                            }
                            break;
                        case eDirection.E_RIGHT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(DiaX, avg + DiaY);

                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(DiaX, avg + space * (i - 1) + DiaY);
                            }
                            break;
                    }
                    ptList.Add(ci.Center);
                    if (i > 0)
                    {
                        if (i == 1 || i == num)
                            spaceList.Add(avg);
                        else
                            spaceList.Add(space);
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateIntervalAvgCircleHatchListByCount(Database db, ref Extents2d ext, Point2d Point, double radius,
double width, double lmax, int num, double DiaX, double DiaY, out List<Point3d> ptList, out List<double> spaceList, out string capString, eDirection eDir = eDirection.E_TOP, bool isBoth = true, string layer = "H点筋")
        {
            ptList = new List<Point3d>();
            spaceList = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 
                double space = Math.Round((width / num), 1);
                double avg = Math.Round((width - space * (num - 2)) * 0.5, 1);

                capString = avg + "+" + (num - 2) + "×" + space + "+" + avg;
                if (avg == space)
                {
                    capString = num + "×" + space;
                }
                for (int i = 0; i <= num; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2) + avg + DiaX, DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg + space * (i - 1) + DiaX, DiaY);
                            }
                            break;
                        case eDirection.E_BOTTOM:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, -DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(avg + DiaX, -DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(avg + space * (i - 2) + avg + DiaX, -DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(avg + space * (i - 1) + DiaX, -DiaY);
                            }
                            break;
                        case eDirection.E_LEFT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(-DiaX, avg + DiaY);
                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(-DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-DiaX, avg + space * (i - 1) + DiaY);
                            }
                            break;
                        case eDirection.E_RIGHT:
                            if (i == 0)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, DiaY);
                            }
                            else if (i == 1)
                            {
                                ci.Center = Point.C3D(DiaX, avg + DiaY);

                            }
                            else if (i == num)
                            {
                                if (isBoth)
                                    ci.Center = Point.C3D(DiaX, avg + space * (i - 2) + avg + DiaY);
                            }
                            else
                            {
                                ci.Center = Point.C3D(DiaX, avg + space * (i - 1) + DiaY);
                            }
                            break;
                    }
                  
                    if (i > 0)
                    {
                        if (i == 1 || i == num)
                            spaceList.Add(avg);
                        else
                            spaceList.Add(space);
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    if (i % 2 == 0||i== num)
                    {
                        ptList.Add(ci.Center);
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt[layer];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateCircleHatchListBySpace(Database db, ref Extents2d ext, Point2d Point, double radius,
double width,  double space,  out List<Point3d> ptList, out List<double> spaceList, out string capString, eDirection eDir = eDirection.E_TOP, string layer = "H点筋")
        {
            ptList = new List<Point3d>();
            spaceList = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 
                int num = (int)((width-radius*2) / space);             
                capString = num  + "×" + space;
                for (int i = 0; i <= num; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            ci.Center = Point.C3D(0,-radius - space * i);
                            break;
                        case eDirection.E_BOTTOM:
                            ci.Center = Point.C3D(0,radius + space * i);
                            break;
                        case eDirection.E_LEFT:
                            ci.Center = Point.C3D(radius + space * i);
                            break;
                        case eDirection.E_RIGHT:
                            ci.Center = Point.C3D(-radius - space * i);
                            break;
                    }
                    ptList.Add(ci.Center);

                    spaceList.Add(space);

                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                }

                #endregion


                tr.Commit();
            }
        }



        /// <summary>
        /// 顶层和底层布筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="Point">（最左边作为起点）参考点</param>
        /// <param name="radius">半径</param>
        /// <param name="topSp">间隔列表</param>
        /// <param name="sacle">比例尺</param>
        /// <param name="isOnLineUpper">是否在线上面</param>
        public static void CreateSingleLineHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
         List<double> topSp, double sacle, double Dia,out List<Point3d> ptLst, bool isOnLineUpper = true, string layer = "H点筋",bool isDrawing=true)
        {
            //radius = radius * sacle;
            ptLst = new List<Point3d>();
            double width = 0;
            width = topSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

                //画线
                Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线

                line.AddVertexAt(0, Point.C2D(0, 0), 0, 0, 0);
                line.AddVertexAt(1, Point.C2D(width + Dia, 0), 0, 0, 0);

                if (isDrawing)
                {
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                }
                #region 
                curWidth = 0;
                for (int i = 0; i < topSp.Count + 1; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    if (isOnLineUpper)
                    {
                        ci.Center = Point.C3D(curWidth + Dia / 2, radius);
                    }
                    else
                    {
                        ci.Center = Point.C3D(curWidth + Dia / 2, -radius);
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    if (isDrawing)
                    {
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));

                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt[layer];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);

                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                    }
                    if (i < topSp.Count)
                        curWidth += topSp[i];
                    ptLst.Add(ci.Center);
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateDoubleBathchHatch(Database db, ref Extents2d ext, Point2d Point, double radius, double rebarDia,int numS,
List<double> topSp, double sacle, double Dia, out List<Point3d> ptLst, bool isAdd = true, bool isLevel = true, bool isBoth = true, string layer = "H点筋")
        {
            //radius = radius * sacle;
            ptLst = new List<Point3d>();
            double width = 0;
            width = topSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

               
                #region 
                curWidth = 0;
                if (rebarDia < 2 * radius)
                    rebarDia = 2 * radius;
                for (int i = 0; i < topSp.Count+1; i++)
                {
                    if (isBoth)
                    {
                        //画圆
                        Circle ci = new Circle();

                        if (isLevel)
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, Dia / 2 + rebarDia);
                            }
                            else
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, -Dia / 2 - rebarDia);
                            }
                        }
                        else
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(Dia / 2 + rebarDia, curWidth + Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-Dia / 2 - rebarDia, curWidth + Dia / 2);
                            }
                        }


                        if (i > 0 && i < topSp.Count)
                        {

                            ci.Radius = radius;
                            ci.LayerId = lt[layer];
                            ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                            recorder.AppendEntity(ci);
                            tr.AddNewlyCreatedDBObject(ci, true);
                            ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                            //圆填充
                            ObjectIdCollection collection = new ObjectIdCollection();
                            collection.Add(ci.ObjectId);
                            Hatch hatch = new Hatch();
                            hatch.Elevation = 0;
                            hatch.HatchStyle = HatchStyle.Normal;
                            hatch.LayerId = lt[layer];
                            hatch.SetDatabaseDefaults();
                            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                            hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                            hatch.EvaluateHatch(true);
                            recorder.AppendEntity(hatch);
                            tr.AddNewlyCreatedDBObject(hatch, true);
                            ptLst.Add(ci.Center);
                        }
                        if (i < topSp.Count)
                            curWidth += topSp[i];
                        
                    }
                    else
                    {

                        //画圆
                        Circle ci = new Circle();
                        if (isLevel)
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, -Dia / 2);
                            }
                        }
                        else
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(Dia / 2, curWidth + Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-Dia / 2, curWidth + Dia / 2);
                            }
                        }
                        ci.Radius = radius;
                        ci.LayerId = lt[layer];
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        if (i > 0 && i < topSp.Count)
                        {
                            recorder.AppendEntity(ci);
                            tr.AddNewlyCreatedDBObject(ci, true);
                            ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                            //圆填充
                            ObjectIdCollection collection = new ObjectIdCollection();
                            collection.Add(ci.ObjectId);
                            Hatch hatch = new Hatch();
                            hatch.Elevation = 0;
                            hatch.HatchStyle = HatchStyle.Normal;
                            hatch.LayerId = lt[layer];
                            hatch.SetDatabaseDefaults();
                            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                            hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                            hatch.EvaluateHatch(true);
                            recorder.AppendEntity(hatch);
                            tr.AddNewlyCreatedDBObject(hatch, true);
                            ptLst.Add(ci.Center);
                        }
                        if (i < topSp.Count)
                            curWidth += topSp[i];

                    }
                }

                #endregion


                tr.Commit();
            }
        }


        public static void CreateSingleBathchHatch(Database db, ref Extents2d ext, Point2d Point, double radius,
    List<double> topSp, double sacle, double Dia, out List<Point3d> ptLst, bool isAdd = true,bool isLevel=true, bool isBoth=true,string layer = "H点筋")
        {
            //radius = radius * sacle;
            ptLst = new List<Point3d>();
            double width = 0;
            width = topSp.Sum();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

                ////画线
                //Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线

                //line.AddVertexAt(0, Point.C2D(0, 0), 0, 0, 0);
                //line.AddVertexAt(1, Point.C2D(width + Dia, 0), 0, 0, 0);

                //recorder.AppendEntity(line);
                //tr.AddNewlyCreatedDBObject(line, true);
                //ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                #region 
                curWidth = 0;
                for (int i = 0; i < topSp.Count + 1; i++)
                {
                    if (isBoth)
                    {
                        //画圆
                        Circle ci = new Circle();
                        if (isLevel)
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, -Dia / 2);
                            }
                        }
                        else
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(Dia / 2, curWidth + Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-Dia / 2, curWidth + Dia / 2);
                            }
                        }
                        ci.Radius = radius;
                        ci.LayerId = lt[layer];
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        recorder.AppendEntity(ci);
                        tr.AddNewlyCreatedDBObject(ci, true);
                        ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                        //圆填充
                        ObjectIdCollection collection = new ObjectIdCollection();
                        collection.Add(ci.ObjectId);
                        Hatch hatch = new Hatch();
                        hatch.Elevation = 0;
                        hatch.HatchStyle = HatchStyle.Normal;
                        hatch.LayerId = lt[layer];
                        hatch.SetDatabaseDefaults();
                        hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                        hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                        hatch.EvaluateHatch(true);
                        recorder.AppendEntity(hatch);
                        tr.AddNewlyCreatedDBObject(hatch, true);
                        if (i < topSp.Count)
                            curWidth += topSp[i];
                        ptLst.Add(ci.Center);
                    }
                    else
                    {
                       
                        //画圆
                        Circle ci = new Circle();
                        if (isLevel)
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(curWidth + Dia / 2, -Dia / 2);
                            }
                        }
                        else
                        {
                            if (isAdd)
                            {
                                ci.Center = Point.C3D(Dia / 2, curWidth + Dia / 2);
                            }
                            else
                            {
                                ci.Center = Point.C3D(-Dia / 2, curWidth + Dia / 2);
                            }
                        }
                        ci.Radius = radius;
                        ci.LayerId = lt[layer];
                        ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                        if (i > 0 && i < topSp.Count)
                        {
                            recorder.AppendEntity(ci);
                            tr.AddNewlyCreatedDBObject(ci, true);
                            ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                            //圆填充
                            ObjectIdCollection collection = new ObjectIdCollection();
                            collection.Add(ci.ObjectId);
                            Hatch hatch = new Hatch();
                            hatch.Elevation = 0;
                            hatch.HatchStyle = HatchStyle.Normal;
                            hatch.LayerId = lt[layer];
                            hatch.SetDatabaseDefaults();
                            hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                            hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                            hatch.EvaluateHatch(true);
                            recorder.AppendEntity(hatch);
                            tr.AddNewlyCreatedDBObject(hatch, true);
                            ptLst.Add(ci.Center);
                        }
                        if (i < topSp.Count)
                            curWidth += topSp[i];
                       
                    }
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateSingleBatchHatchByPointList(Database db, ref Extents2d ext, double radius,
List<Point3d> ptLst, double sacle, double Dia, bool isAdd = true, bool isLevel = true, string layer = "H点筋")
        {
  
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                #region 

                for (int i = 0; i < ptLst.Count; i++)
                {
                    //画圆
                    Circle ci = new Circle();
                    if (isLevel)
                    {
                        if (isAdd)
                        {
                            ci.Center = ptLst[i].C3D(Dia / 2, Dia / 2);
                        }
                        else
                        {
                            ci.Center = ptLst[i].C3D( Dia / 2, -Dia / 2);
                        }
                    }
                    else
                    {
                        if (isAdd)
                        {
                            ci.Center = ptLst[i].C3D(Dia / 2,  Dia / 2);
                        }
                        else
                        {
                            ci.Center = ptLst[i].C3D(-Dia / 2, Dia / 2);
                        }
                    }
                    ci.Radius = radius;
                    ci.LayerId = lt[layer];
                    ci.SetDatabaseDefaults();//用来把圆的颜色、图层、线型、打印样式、可见性等属性设为实体所在的数据库的默认值
                    recorder.AppendEntity(ci);
                    tr.AddNewlyCreatedDBObject(ci, true);
                    ext = ext.Add(new Extents2d(ci.Bounds.Value.MinPoint.C2D(), ci.Bounds.Value.MaxPoint.C2D()));
                    //圆填充
                    ObjectIdCollection collection = new ObjectIdCollection();
                    collection.Add(ci.ObjectId);
                    Hatch hatch = new Hatch();
                    hatch.Elevation = 0;
                    hatch.HatchStyle = HatchStyle.Normal;
                    hatch.LayerId = lt[layer];
                    hatch.SetDatabaseDefaults();
                    hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
                    hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
                    hatch.EvaluateHatch(true);
                    recorder.AppendEntity(hatch);
                    tr.AddNewlyCreatedDBObject(hatch, true);
                  
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateBatchLine(Database db, ref Extents2d ext, Point2d Point,
 List<double> lstSp, double len, out List<Point3d> ptLst,out List<double> lstDimSp, bool isLevel = true, string layer = "H钢筋")
        {
            ptLst = new List<Point3d>();
            lstDimSp = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;

              
                #region 
                curWidth = 0;
                for (int i = 0; i < lstSp.Count - 1; i++)
                {
                    curWidth += lstSp[i];
                    if (i != 0)
                        lstDimSp.Add(lstSp[i]);
                    //画线
                    Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线
                    if (isLevel)
                    {
                        line.AddVertexAt(0, Point.C2D(0, curWidth), 0, 0, 0);
                        line.AddVertexAt(1, Point.C2D(len, curWidth), 0, 0, 0);
                        ptLst.Add(Point.C3D(0, curWidth));
                    }
                    else
                    {
                        line.AddVertexAt(0, Point.C2D(curWidth, 0), 0, 0, 0);
                        line.AddVertexAt(1, Point.C2D(curWidth, len), 0, 0, 0);
                        ptLst.Add(Point.C3D(curWidth));
                    }
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                }

                #endregion


                tr.Commit();
            }
        }

        public static void CreateBatchLineNew(Database db, ref Extents2d ext, Point2d Point,
List<double> lstSp, double len, out List<Point3d> ptLst, out List<double> lstDimSp, bool isLevel = true, string layer = "H钢筋")
        {
            ptLst = new List<Point3d>();
            lstDimSp = new List<double>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                double curWidth = 0;


                #region 
                curWidth = 0;
                for (int i = 0; i < lstSp.Count; i++)
                {
                    curWidth += lstSp[i];
                 
                    lstDimSp.Add(lstSp[i]);
                    //画线
                    Polyline line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线
                    if (isLevel)
                    {
                        if (i == 0)
                        {
                            line.AddVertexAt(0, Point.C2D(0, 0), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(len, 0), 0, 0, 0);
                            ptLst.Add(Point.C3D(0, 0));
                            recorder.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线
                            line.AddVertexAt(0, Point.C2D(0, curWidth), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(len, curWidth), 0, 0, 0);
                            ptLst.Add(Point.C3D(0, curWidth));
                        }
                        else
                        {
                            line.AddVertexAt(0, Point.C2D(0, curWidth), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(len, curWidth), 0, 0, 0);
                            ptLst.Add(Point.C3D(0, curWidth));
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            line.AddVertexAt(0, Point.C2D(0, 0), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(0, len), 0, 0, 0);
                            ptLst.Add(Point.C3D());
                            recorder.AppendEntity(line);
                            tr.AddNewlyCreatedDBObject(line, true);
                            line = new Polyline() { Closed = false, LayerId = lt[layer] };//定义不封闭的Polyline 平面虚线
                            line.AddVertexAt(0, Point.C2D(curWidth, 0), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(curWidth, len), 0, 0, 0);
                            ptLst.Add(Point.C3D(curWidth));
                        }
                        else
                        {
                            line.AddVertexAt(0, Point.C2D(curWidth, 0), 0, 0, 0);
                            line.AddVertexAt(1, Point.C2D(curWidth, len), 0, 0, 0);
                            ptLst.Add(Point.C3D(curWidth));
                        }
                    }
                    recorder.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                    ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                }

                #endregion


                tr.Commit();
            }
        }


        public static void CreateLineList(Database db, ref Extents2d ext,
  List<Point3d> lst, eDirection eDir = eDirection.E_TOP,  double len=30 ,string layer = "H粗线")
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                switch (eDir)
                {
                    case eDirection.E_TOP:
                        PLPloter.AddLine(db,lst[0].C2D(0, len), lst[lst.Count - 1].C2D(0, len), ref ext, layer);
                       
                        break;
                    case eDirection.E_BOTTOM:
                        PLPloter.AddLine(db,lst[0].C2D(0, -len), lst[lst.Count - 1].C2D(0, -len), ref ext, layer);
                        break;
                    case eDirection.E_LEFT:
                        PLPloter.AddLine(db,lst[0].C2D( -len), lst[lst.Count - 1].C2D(-len), ref ext, layer);
                       
                        break;
                    case eDirection.E_RIGHT:
                        PLPloter.AddLine(db,lst[0].C2D(len), lst[lst.Count - 1].C2D(len), ref ext, layer);
                        break;
                }              
              
                #region 

                for (int i = 0; i < lst.Count; i++)
                {

                    switch (eDir)
                    {
                        case eDirection.E_TOP:
                            PLPloter.AddLine(db,lst[i].C2D(0, len), lst[i].C2D(0, len-10), ref ext, layer);
                            break;
                        case eDirection.E_BOTTOM:
                            PLPloter.AddLine(db,lst[i].C2D(0, -len), lst[i].C2D(0, -len+10), ref ext, layer);
                            break;
                        case eDirection.E_LEFT:
                            PLPloter.AddLine(db,lst[i].C2D(-len), lst[i].C2D(-len + 10), ref ext, layer);
                            break;
                        case eDirection.E_RIGHT:
                            PLPloter.AddLine(db,lst[i].C2D(len), lst[i].C2D(len - 10), ref ext, layer);
                            break;
                    }
                }

                #endregion


                tr.Commit();
            }
        }

        //直线大样
        public static void AddLineSample(Point2d stPoint, Point2d endPoint, ref Extents2d ext, string layer, eSampleType etype= eSampleType.UN, double len = 8, double R=2,double scale = 1)
        {

            Database db = HostApplicationServices.WorkingDatabase;
            Line line = new Line(stPoint.C3D(), endPoint.C3D());
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                switch(etype)
                {
                    case eSampleType.UN:
                        break;
                    case eSampleType.UT:
                        Line lineT1 = new Line(stPoint.C3D(), stPoint.C3D(0, len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineT1);
                        tr.AddNewlyCreatedDBObject(lineT1, true);
                        ext = ext.Add(new Extents2d(lineT1.Bounds.Value.MinPoint.C2D(), lineT1.Bounds.Value.MaxPoint.C2D()));
                        Line lineT2 = new Line(endPoint.C3D(), endPoint.C3D(0, len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineT2);
                        tr.AddNewlyCreatedDBObject(lineT2, true);
                        ext = ext.Add(new Extents2d(lineT2.Bounds.Value.MinPoint.C2D(), lineT2.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case eSampleType.UB:
                        Line lineB1 = new Line(stPoint.C3D(), stPoint.C3D(0, -len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineB1);
                        tr.AddNewlyCreatedDBObject(lineB1, true);
                        ext = ext.Add(new Extents2d(lineB1.Bounds.Value.MinPoint.C2D(), lineB1.Bounds.Value.MaxPoint.C2D()));
                        Line lineB2 = new Line(endPoint.C3D(), endPoint.C3D(0, -len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineB2);
                        tr.AddNewlyCreatedDBObject(lineB2, true);
                        ext = ext.Add(new Extents2d(lineB2.Bounds.Value.MinPoint.C2D(), lineB2.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case eSampleType.UL:
                        Line lineL1 = new Line(stPoint.C3D(-len), stPoint.C3D()) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineL1);
                        tr.AddNewlyCreatedDBObject(lineL1, true);
                        ext = ext.Add(new Extents2d(lineL1.Bounds.Value.MinPoint.C2D(), lineL1.Bounds.Value.MaxPoint.C2D()));
                        Line lineL2 = new Line(endPoint.C3D(-len), endPoint.C3D()) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineL2);
                        tr.AddNewlyCreatedDBObject(lineL2, true);
                        ext = ext.Add(new Extents2d(lineL2.Bounds.Value.MinPoint.C2D(), lineL2.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case eSampleType.UR:
                        Line lineR1 = new Line(stPoint.C3D(), stPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineR1);
                        tr.AddNewlyCreatedDBObject(lineR1, true);
                        ext = ext.Add(new Extents2d(lineR1.Bounds.Value.MinPoint.C2D(), lineR1.Bounds.Value.MaxPoint.C2D()));
                        Line lineR2 = new Line(endPoint.C3D(), endPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineR2);
                        tr.AddNewlyCreatedDBObject(lineR2, true);
                        ext = ext.Add(new Extents2d(lineR2.Bounds.Value.MinPoint.C2D(), lineR2.Bounds.Value.MaxPoint.C2D()));
                   
                        break;
                    case eSampleType.UTC:
                      
                        Line lineC2 = new Line(endPoint.C3D(), endPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineC2);
                        tr.AddNewlyCreatedDBObject(lineC2, true);
                        ext = ext.Add(new Extents2d(lineC2.Bounds.Value.MinPoint.C2D(), lineC2.Bounds.Value.MaxPoint.C2D()));
                        Arc arc1 = new Arc(stPoint.C3D(R, 0), R, GeTools.DegreeToRadian(45), GeTools.DegreeToRadian(180)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arc1);
                        tr.AddNewlyCreatedDBObject(arc1, true);
                        ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.C2D(), arc1.Bounds.Value.MaxPoint.C2D()));
                        Line lineC1 = new Line(arc1.StartPoint.C3D(), arc1.StartPoint.C3D(len * Math.Sin(GeTools.DegreeToRadian(45)), -len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineC1);
                        tr.AddNewlyCreatedDBObject(lineC1, true);

                        break;
                    case eSampleType.UTLC:

                        Line lineLC2 = new Line(endPoint.C3D(), endPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLC2);
                        tr.AddNewlyCreatedDBObject(lineLC2, true);
                        ext = ext.Add(new Extents2d(lineLC2.Bounds.Value.MinPoint.C2D(), lineLC2.Bounds.Value.MaxPoint.C2D()));
                        Arc arcL1 = new Arc(stPoint.C3D(-R, 0), R, GeTools.DegreeToRadian(0), GeTools.DegreeToRadian(135)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcL1);
                        tr.AddNewlyCreatedDBObject(arcL1, true);
                        ext = ext.Add(new Extents2d(arcL1.Bounds.Value.MinPoint.C2D(), arcL1.Bounds.Value.MaxPoint.C2D()));
                        Line lineLTC2 = new Line(arcL1.EndPoint.C3D(), arcL1.EndPoint.C3D(-len * Math.Sin(GeTools.DegreeToRadian(45)), -len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLTC2);
                        tr.AddNewlyCreatedDBObject(lineLTC2, true);
                        break;
                    case eSampleType.UBC:
                        Line line1 = new Line(stPoint.C3D(), stPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(line1);
                        tr.AddNewlyCreatedDBObject(line1, true);
                        ext = ext.Add(new Extents2d(line1.Bounds.Value.MinPoint.C2D(), line1.Bounds.Value.MaxPoint.C2D()));            
                        Arc arc2 = new Arc(endPoint.C3D(R, 0), R, GeTools.DegreeToRadian(180), GeTools.DegreeToRadian(315)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arc2);
                        tr.AddNewlyCreatedDBObject(arc2, true);
                        ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.C2D(), arc2.Bounds.Value.MaxPoint.C2D()));
                        Line line2 = new Line(arc2.EndPoint.C3D(), arc2.EndPoint.C3D(len*Math.Sin(GeTools.DegreeToRadian(45)), len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(line2);
                        tr.AddNewlyCreatedDBObject(line2, true);
                        ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.C2D(), line2.Bounds.Value.MaxPoint.C2D()));
                        break;
                    case eSampleType.UBLC:
                        Line lineLC1 = new Line(stPoint.C3D(), stPoint.C3D(-len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLC1);
                        tr.AddNewlyCreatedDBObject(lineLC1, true);
                        ext = ext.Add(new Extents2d(lineLC1.Bounds.Value.MinPoint.C2D(), lineLC1.Bounds.Value.MaxPoint.C2D()));
                        Arc arcL2 = new Arc(endPoint.C3D(R, 0), R, GeTools.DegreeToRadian(225), GeTools.DegreeToRadian(0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcL2);
                        tr.AddNewlyCreatedDBObject(arcL2, true);
                        ext = ext.Add(new Extents2d(arcL2.Bounds.Value.MinPoint.C2D(), arcL2.Bounds.Value.MaxPoint.C2D()));
                        Line lineLBC2 = new Line(arcL2.StartPoint.C3D(), arcL2.StartPoint.C3D(-len * Math.Sin(GeTools.DegreeToRadian(45)), len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLBC2);
                        tr.AddNewlyCreatedDBObject(lineLBC2, true);
                        break;
                    case eSampleType.UC:

                        Arc arcu1 = new Arc(stPoint.C3D(0, R), R, GeTools.DegreeToRadian(90), GeTools.DegreeToRadian(270)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcu1);
                        tr.AddNewlyCreatedDBObject(arcu1, true);
                        ext = ext.Add(new Extents2d(arcu1.Bounds.Value.MinPoint.C2D(), arcu1.Bounds.Value.MaxPoint.C2D()));
                        Line lineCu1 = new Line(arcu1.StartPoint.C3D(), arcu1.StartPoint.C3D(len, 0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineCu1);
                        tr.AddNewlyCreatedDBObject(lineCu1, true);

                        Arc arcu2 = new Arc(endPoint.C3D(0, R), R, GeTools.DegreeToRadian(270), GeTools.DegreeToRadian(90)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcu2);
                        tr.AddNewlyCreatedDBObject(arcu2, true);
                        ext = ext.Add(new Extents2d(arcu2.Bounds.Value.MinPoint.C2D(), arcu2.Bounds.Value.MaxPoint.C2D()));
                        Line lineCu2 = new Line(arcu2.StartPoint.C3D(), arcu2.StartPoint.C3D(-len, 0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineCu2);
                        tr.AddNewlyCreatedDBObject(lineCu2, true);

                        break;
                    default:
                        break;
                }
                line.LayerId = lt[layer];
                line.LinetypeScale = scale;
                modelSpace.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                tr.Commit();
            }          
        }

        public static void AddLineSample2Dim(Database db, Point2d point, ref Extents2d ext, string layer, eDB N, eSampleType etype = eSampleType.UN, string txtmid="", double lenline = 70, double len = 5, double R = 0.5, double scale = 1,double textH=2,bool isVisible=true)
        {

            //Database db = HostApplicationServices.WorkingDatabase;
            Point2d stPoint= point.C2D(-lenline*0.5), endPoint= point.C2D(-lenline * 0.5);
           
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                string D = ((int)N).ToString();
                double dia = double.Parse(D);
                double value = dia;
                if (dia > 16)
                    value = dia * 1.4;
                else
                    value = dia * 1.25;
                switch (etype)
                {
                    case eSampleType.UN:
                    case eSampleType.UB:
                    case eSampleType.UT:
                    case eSampleType.UC:
                        break;
                    default:
                        lenline = 15;
                        break;
                }
                switch (etype)
                {
                    case eSampleType.UN:
                        point = point.C2D(0, -2 * scale);
                        stPoint = point.C2D(-lenline * 0.5);
                        endPoint = point.C2D(lenline * 0.5);
                        break;
                    case eSampleType.UB:
                    case eSampleType.UC:
                        stPoint = point.C2D(-lenline * 0.5);
                        endPoint = point.C2D(lenline * 0.5);

                        break;
                    case eSampleType.UT:
                        stPoint = point.C2D(-lenline * 0.5, len * 0.5);
                        endPoint = point.C2D(lenline * 0.5, len * 0.5);
                        break;
                    default:
                        stPoint = point.C2D(0, -lenline * 0.5);
                        endPoint = point.C2D(0, lenline * 0.5);
                        break;
                }
                switch (etype)
                {
                    case eSampleType.UN:
                        TextPloter.AddDBText(db,point.C3D(), ref ext, txtmid, scale, textH, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                        break;
                    case eSampleType.UT:
                        stPoint = stPoint.C2D(0, -len);
                        endPoint = endPoint.C2D(0, -len);
                        Line lineT1 = new Line(stPoint.C3D(), stPoint.C3D(0, len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineT1);
                        tr.AddNewlyCreatedDBObject(lineT1, true);
                        ext = ext.Add(new Extents2d(lineT1.Bounds.Value.MinPoint.C2D(), lineT1.Bounds.Value.MaxPoint.C2D()));
                        Line lineT2 = new Line(endPoint.C3D(), endPoint.C3D(0, len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineT2);
                        tr.AddNewlyCreatedDBObject(lineT2, true);
                        ext = ext.Add(new Extents2d(lineT2.Bounds.Value.MinPoint.C2D(), lineT2.Bounds.Value.MaxPoint.C2D()));

                        TextPloter.AddDBText(db,point.C3D(0, -len*0.5), ref ext, txtmid, scale, textH, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(-4 * scale, len), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(270));
                            TextPloter.AddDBText(db,endPoint.C3D(0.5 * scale, len), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(270));
                        }
                        break;
                    case eSampleType.UB:
                       
                        Line lineB1 = new Line(stPoint.C3D(), stPoint.C3D(0, -len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineB1);
                        tr.AddNewlyCreatedDBObject(lineB1, true);
                        ext = ext.Add(new Extents2d(lineB1.Bounds.Value.MinPoint.C2D(), lineB1.Bounds.Value.MaxPoint.C2D()));
                        Line lineB2 = new Line(endPoint.C3D(), endPoint.C3D(0, -len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineB2);
                        tr.AddNewlyCreatedDBObject(lineB2, true);
                        ext = ext.Add(new Extents2d(lineB2.Bounds.Value.MinPoint.C2D(), lineB2.Bounds.Value.MaxPoint.C2D()));

                        TextPloter.AddDBText(db,point.C3D(), ref ext, txtmid, scale, textH, "SRB.HT", 0, TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(-4 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(270));
                            TextPloter.AddDBText(db,endPoint.C3D(0.5 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(270));
                        }
                        break;
                    case eSampleType.UL:
                        Line lineL1 = new Line(stPoint.C3D(-len), stPoint.C3D()) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineL1);
                        tr.AddNewlyCreatedDBObject(lineL1, true);
                        ext = ext.Add(new Extents2d(lineL1.Bounds.Value.MinPoint.C2D(), lineL1.Bounds.Value.MaxPoint.C2D()));
                        Line lineL2 = new Line(endPoint.C3D(-len), endPoint.C3D()) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineL2);
                        tr.AddNewlyCreatedDBObject(lineL2, true);
                        ext = ext.Add(new Extents2d(lineL2.Bounds.Value.MinPoint.C2D(), lineL2.Bounds.Value.MaxPoint.C2D()));

                        TextPloter.AddDBText(db,point.C3D(0,3*scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270), TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(0, -3.5 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                            TextPloter.AddDBText(db,endPoint.C3D(0, 0 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                        }
                        break;
                    case eSampleType.UR:
                        Line lineR1 = new Line(stPoint.C3D(), stPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineR1);
                        tr.AddNewlyCreatedDBObject(lineR1, true);
                        ext = ext.Add(new Extents2d(lineR1.Bounds.Value.MinPoint.C2D(), lineR1.Bounds.Value.MaxPoint.C2D()));
                        Line lineR2 = new Line(endPoint.C3D(), endPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineR2);
                        tr.AddNewlyCreatedDBObject(lineR2, true);
                        ext = ext.Add(new Extents2d(lineR2.Bounds.Value.MinPoint.C2D(), lineR2.Bounds.Value.MaxPoint.C2D()));

                        TextPloter.AddDBText(db,point.C3D(-3.5 * scale, 3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270),TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(0, -3.5 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                            TextPloter.AddDBText(db,endPoint.C3D(0, 0), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                        }
                        break;
                    case eSampleType.UBC:

                        Line lineC2 = new Line(endPoint.C3D(), endPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineC2);
                        tr.AddNewlyCreatedDBObject(lineC2, true);
                        ext = ext.Add(new Extents2d(lineC2.Bounds.Value.MinPoint.C2D(), lineC2.Bounds.Value.MaxPoint.C2D()));
                        Arc arc1 = new Arc(stPoint.C3D(R, 0), R, GeTools.DegreeToRadian(180), GeTools.DegreeToRadian(315)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arc1);
                        tr.AddNewlyCreatedDBObject(arc1, true);
                        ext = ext.Add(new Extents2d(arc1.Bounds.Value.MinPoint.C2D(), arc1.Bounds.Value.MaxPoint.C2D()));
                        Line lineC1 = new Line(arc1.EndPoint.C3D(), arc1.EndPoint.C3D(len * Math.Sin(GeTools.DegreeToRadian(45)), len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineC1);
                        tr.AddNewlyCreatedDBObject(lineC1, true);

                        TextPloter.AddDBText(db,point.C3D(-3.5*scale, 3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270), TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(3 * scale, -3 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(45));
                            TextPloter.AddDBText(db,endPoint.C3D(), ref ext, value.ToString(), scale, textH, "SRB.HT");
                        }
                        break;
                    case eSampleType.UBLC:

                        Line lineLC2 = new Line(endPoint.C3D(), endPoint.C3D(-len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLC2);
                        tr.AddNewlyCreatedDBObject(lineLC2, true);
                        ext = ext.Add(new Extents2d(lineLC2.Bounds.Value.MinPoint.C2D(), lineLC2.Bounds.Value.MaxPoint.C2D()));
                        Arc arcL1 = new Arc(stPoint.C3D(-R, 0), R, GeTools.DegreeToRadian(225), GeTools.DegreeToRadian(0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcL1);
                        tr.AddNewlyCreatedDBObject(arcL1, true);
                        ext = ext.Add(new Extents2d(arcL1.Bounds.Value.MinPoint.C2D(), arcL1.Bounds.Value.MaxPoint.C2D()));
                        Line lineLTC2 = new Line(arcL1.StartPoint.C3D(), arcL1.StartPoint.C3D(-len * Math.Sin(GeTools.DegreeToRadian(45)), len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLTC2);
                        tr.AddNewlyCreatedDBObject(lineLTC2, true);

                        TextPloter.AddDBText(db,point.C3D(0, 3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270), TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(-len, 3 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(315));
                            TextPloter.AddDBText(db,endPoint.C3D(-len), ref ext, value.ToString(), scale, textH, "SRB.HT");
                        }
                        break;
                    case eSampleType.UTC:
                        Line line1 = new Line(stPoint.C3D(), stPoint.C3D(len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(line1);
                        tr.AddNewlyCreatedDBObject(line1, true);
                        ext = ext.Add(new Extents2d(line1.Bounds.Value.MinPoint.C2D(), line1.Bounds.Value.MaxPoint.C2D()));
                        Arc arc2 = new Arc(endPoint.C3D(R, 0), R, GeTools.DegreeToRadian(45), GeTools.DegreeToRadian(180)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arc2);
                        tr.AddNewlyCreatedDBObject(arc2, true);
                        ext = ext.Add(new Extents2d(arc2.Bounds.Value.MinPoint.C2D(), arc2.Bounds.Value.MaxPoint.C2D()));
                        Line line2 = new Line(arc2.StartPoint.C3D(), arc2.StartPoint.C3D(len * Math.Sin(GeTools.DegreeToRadian(45)), -len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(line2);
                        tr.AddNewlyCreatedDBObject(line2, true);
                        ext = ext.Add(new Extents2d(line2.Bounds.Value.MinPoint.C2D(), line2.Bounds.Value.MaxPoint.C2D()));

                        TextPloter.AddDBText(db,point.C3D(-3.5 * scale, 3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270), TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(0, -3 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                            TextPloter.AddDBText(db,endPoint.C3D(), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(315));
                        }
                        break;
                    case eSampleType.UTLC:
                        Line lineLC1 = new Line(stPoint.C3D(), stPoint.C3D(-len)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLC1);
                        tr.AddNewlyCreatedDBObject(lineLC1, true);
                        ext = ext.Add(new Extents2d(lineLC1.Bounds.Value.MinPoint.C2D(), lineLC1.Bounds.Value.MaxPoint.C2D()));
                        Arc arcL2 = new Arc(endPoint.C3D(-R, 0), R, GeTools.DegreeToRadian(0), GeTools.DegreeToRadian(135)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcL2);
                        tr.AddNewlyCreatedDBObject(arcL2, true);
                        ext = ext.Add(new Extents2d(arcL2.Bounds.Value.MinPoint.C2D(), arcL2.Bounds.Value.MaxPoint.C2D()));
                        Line lineLBC2 = new Line(arcL2.EndPoint.C3D(), arcL2.EndPoint.C3D(-len * Math.Sin(GeTools.DegreeToRadian(45)), -len * Math.Cos(GeTools.DegreeToRadian(45)))) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineLBC2);
                        tr.AddNewlyCreatedDBObject(lineLBC2, true);

                        TextPloter.AddDBText(db,point.C3D(0, 3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(270), TextHorizontalMode.TextCenter);
                        if (isVisible)
                        {
                            TextPloter.AddDBText(db,stPoint.C3D(-len, -3.5 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", 0);
                            TextPloter.AddDBText(db,endPoint.C3D(-len, -3 * scale), ref ext, value.ToString(), scale, textH, "SRB.HT", GeTools.DegreeToRadian(45));
                        }
                        break;
                    case eSampleType.UC:
                  
                        Arc arcu1 = new Arc(stPoint.C3D(0, R), R, GeTools.DegreeToRadian(90), GeTools.DegreeToRadian(270)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcu1);
                        tr.AddNewlyCreatedDBObject(arcu1, true);
                        ext = ext.Add(new Extents2d(arcu1.Bounds.Value.MinPoint.C2D(), arcu1.Bounds.Value.MaxPoint.C2D()));
                        Line lineCu1 = new Line(arcu1.StartPoint.C3D(), arcu1.StartPoint.C3D(len , 0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineCu1);
                        tr.AddNewlyCreatedDBObject(lineCu1, true);

                        Arc arcu2 = new Arc(endPoint.C3D(0, R), R, GeTools.DegreeToRadian(270), GeTools.DegreeToRadian(90)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity((Entity)arcu2);
                        tr.AddNewlyCreatedDBObject(arcu2, true);
                        ext = ext.Add(new Extents2d(arcu2.Bounds.Value.MinPoint.C2D(), arcu2.Bounds.Value.MaxPoint.C2D()));
                        Line lineCu2 = new Line(arcu2.StartPoint.C3D(), arcu2.StartPoint.C3D(-len , 0)) { LayerId = lt[layer] };
                        modelSpace.AppendEntity(lineCu2);
                        tr.AddNewlyCreatedDBObject(lineCu2, true);

                        TextPloter.AddDBText(db,point.C3D(0, -3 * scale), ref ext, txtmid, scale, textH, "SRB.HT", GeTools.DegreeToRadian(0), TextHorizontalMode.TextCenter);                     
                        break;
                    default:
                        break;
                }
                Line line = new Line(stPoint.C3D(), endPoint.C3D());
                line.LayerId = lt[layer];
                line.LinetypeScale = scale;
                modelSpace.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                ext = ext.Add(new Extents2d(line.Bounds.Value.MinPoint.C2D(), line.Bounds.Value.MaxPoint.C2D()));
                tr.Commit();
            }
        }

        public static void AddLineArrowDim(Database db, Point2d stPoint, List<Point2d> lst, ref Extents2d ext, string text, string textC, string layer, eArrowLocation eDir = eArrowLocation.LT, double scale = 1, bool hafeArrow = true)
        {
           
            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1].C2D(), ref ext, layer);                   
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1], ref ext, layer);
                    break;
            }
        
            double w = 0;
            switch (eDir)
            {
                case eArrowLocation.LT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.LB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.2* scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.5 * scale,2*scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.RB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.TB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2* scale, -2.2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, -2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
            }
            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-5,-4), lst[i].C2D(5,4), ref ext, layer);
                    }
                    break;
                case eArrowLocation.RT :
                case eArrowLocation.RB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-5, 4), lst[i].C2D(5, -4), ref ext, layer);
                    }
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6,8), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-4,5), lst[i].C2D(4, -5), ref ext, layer);
                    }
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-4,-5), lst[i].C2D(4, 5), ref ext, layer);
                    }
                    break;
            }
        }
        public static void AddLineArrowDim(Database db, List<Point3d> lst, ref Extents2d ext, string text, string textC, string layer, eArrowLocation eDir = eArrowLocation.LT, double scale = 1, bool hafeArrow = true)
        {

            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,lst[0].C2D(), lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,lst[0].C2D(), lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,lst[0].C2D(), lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,lst[0].C2D(), lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
            }

            double w = 0;
            switch (eDir)
            {
                case eArrowLocation.LT:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(-2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.LB:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.RB:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(-2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.TB:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2 * scale, -2.2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BB:
                    TextPloter.AddDBTextWithSCirle(db,lst[0].C2D().C3D(2 * scale, -2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,lst[0].C2D(), lst[0].C2D().C2D(w), ref ext, layer);
                    break;
            }
            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-5, -4), lst[i].C2D(5, 4), ref ext, layer);
                    }
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-5, 4), lst[i].C2D(5, -4), ref ext, layer);
                    }
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-4, 5), lst[i].C2D(4, -5), ref ext, layer);
                    }
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (hafeArrow)
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                        else
                            PLPloter.AddLine(db,lst[i].C2D(-4, -5), lst[i].C2D(4, 5), ref ext, layer);
                    }
                    break;
            }
        }

        public static void AddLineBothArrowDim(Database db, Point2d stPoint, List<Point2d> lst, ref Extents2d ext, string text, string textC, string layer, eArrowLocation eDir = eArrowLocation.LT, double scale = 1, bool hafeArrow = true)
        {

            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1], ref ext, layer);
                    break;
            }

            double w = 0;
            switch (eDir)
            {
                case eArrowLocation.LT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.LB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.RB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.TB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, -2.2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, -2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
            }
            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-4, -3), lst[i].C2D(4, 3), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0 )
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-4, 3), lst[i].C2D(4, -3), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0 )
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, 8), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, -8), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-3, 4), lst[i].C2D(3, -4), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, 8), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, -8), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-3, -3), lst[i].C2D(3, 4), ref ext, layer);
                        }
                    }
                    break;
            }
        }
        public static void AddLineBothArrowDim(Database db, Point2d stPoint, List<Point3d> lst, ref Extents2d ext, string text, string textC, string layer, eArrowLocation eDir = eArrowLocation.LT, double scale = 1, bool hafeArrow = true)
        {

            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    lst = lst.OrderBy(o => o.X).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[0].C2D(), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    lst = lst.OrderBy(o => o.Y).ToList();
                    PLPloter.AddLine(db,stPoint, lst[lst.Count - 1].C2D(), ref ext, layer);
                    break;
            }

            double w = 0;
            switch (eDir)
            {
                case eArrowLocation.LT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.LB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.RT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2.5 * scale, 2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(90));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, w), ref ext, layer);
                    break;
                case eArrowLocation.RB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(-2.2 * scale, -2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(270));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(0, -w), ref ext, layer);
                    break;
                case eArrowLocation.TT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.TB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, -2.2 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BT:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, 2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
                case eArrowLocation.BB:
                    TextPloter.AddDBTextWithSCirle(db,stPoint.C3D(2 * scale, -2.5 * scale), ref ext, text, textC, scale, out w, GeTools.DegreeToRadian(0));
                    PLPloter.AddLine(db,stPoint, stPoint.C2D(w), ref ext, layer);
                    break;
            }
            switch (eDir)
            {
                case eArrowLocation.LT:
                case eArrowLocation.LB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-4, -3), lst[i].C2D(4, 3), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.RT:
                case eArrowLocation.RB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, 6), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-8, -6), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(8, -6), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-4, 3), lst[i].C2D(4, -3), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.TT:
                case eArrowLocation.TB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, 8), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, -8), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-3, 4), lst[i].C2D(3, -4), ref ext, layer);
                        }
                    }
                    break;
                case eArrowLocation.BT:
                case eArrowLocation.BB:
                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (i == 0)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, 8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, 8), ref ext, layer);
                        }
                        else if (i == lst.Count - 1)
                        {
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(6, -8), ref ext, layer);
                        }
                        else
                        {
                            if (hafeArrow)
                                PLPloter.AddLine(db,lst[i].C2D(), lst[i].C2D(-6, -8), ref ext, layer);
                            else
                                PLPloter.AddLine(db,lst[i].C2D(-3, -3), lst[i].C2D(3, 4), ref ext, layer);
                        }
                    }
                    break;
            }
        }

        /// <summary>
        /// 钢筋工点图
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <param name="T1"></param>
        /// <param name="bound">左右/上下元素个数分界线</param>
        /// <param name="midbound">左右/上下元素个数分界线</param>
        /// <param name="scale"></param>
        public static void CreateRebarPointLine(Database db, ref Extents2d ext, eDirection direction,
            List<Point3d> list, string T1, int bound, int midbound, double scale = 100, bool isleft = false, double height = 10 ,string layer="H标注")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
               
                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));
                switch (direction)
                {
                    case eDirection.E_LEFT:
                        {
                            list = list.OrderByDescending(o => o.Y).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(-height, pointSpace).Y - list[0].C2D(-height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(-height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(-height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(-height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_RIGHT:
                        {
                            list = list.OrderByDescending(o => o.Y).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(height, pointSpace).Y - list[0].C2D(height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_TOP:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            list = list.OrderBy(o => o.X).ToList();
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X - 2.5 * 2 * scale;
                            if (isleft)
                            {
                                width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X;
                            }
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, -height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, -height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            if (isleft)
                            {
                                pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace + 5 * scale, -height), 0, 0, 0);
                                pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl4);
                                DimPloter.CircularMark(db, ref ext, list[list.Count - 1].C3D(-pointSpace + 5 * scale, -height),
                                T1, Extensions.curFont, scale);
                            }
                            else
                                // 圆形标记
                                DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, -height),
                                    T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_BOTTOM:
                        {
                            list = list.OrderBy(o => o.X).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, height).X - list[0].C2D(pointSpace, height).X - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, height),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    default:
                        break;
                }
                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        public static void CreateRebarPointLineNew(Database db, ref Extents2d ext, eDirection direction,
         List<Point3d> list, string T1, int bound, int midbound, double scale = 100, bool isleft = false, double height = 10, string layer = "H标注")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制

                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));
                switch (direction)
                {
                    case eDirection.E_LEFT:
                        {
                            list = list.OrderByDescending(o => o.Y).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 3 - 3 - midbound; i < list.Count / 3 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(-height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count*2 / 3 + 3; i < list.Count * 2 / 3 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(-height, pointSpace).Y - list[0].C2D(-height, -pointSpace).Y);
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(-height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(-height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(-height - 2.5 * scale*2, -pointSpace - width / 2 ),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_RIGHT:
                        {
                            list = list.OrderByDescending(o => o.Y).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) + 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 3 - 3 - midbound; i < list.Count / 3 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(height, -pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count * 2 / 3 + 3; i < list.Count * 2 / 3 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(height, pointSpace), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = Math.Abs(list[list.Count - 1].C2D(height, pointSpace).Y - list[0].C2D(height, -pointSpace).Y) - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(height, -pointSpace), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(height, -pointSpace - width / 2), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(height, pointSpace + width / 2), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(height, pointSpace), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(height - 2.5 * scale, -pointSpace - width / 2 - 2.5 * scale),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_TOP:
                        {
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            list = list.OrderBy(o => o.X).ToList();
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 3 - 3 - midbound; i < list.Count / 3 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count * 2 / 3 + 3; i < list.Count * 2 / 3 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X - 2.5 * 2 * scale;
                            if (isleft)
                            {
                                width = list[list.Count - 1].C2D(-pointSpace, -height).X - list[0].C2D(pointSpace, -height).X;
                            }
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, -height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, -height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            if (isleft)
                            {
                                pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace + 5 * scale, -height), 0, 0, 0);
                                pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, -height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl4);
                                DimPloter.CircularMark(db, ref ext, list[list.Count - 1].C3D(-pointSpace + 5 * scale, -height),
                                T1, Extensions.curFont, scale);
                            }
                            else
                                // 圆形标记
                                DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, -height),
                                    T1, Extensions.curFont, scale);
                            break;
                        }
                    case eDirection.E_BOTTOM:
                        {
                            list = list.OrderBy(o => o.X).ToList();
                            //if (Math.Abs(list[0].X - list[list.Count - 1].X) - 2.5 * scale <= pointSpace * (list.Count - 1))
                            //    break;
                            // 左边
                            for (int i = 0; i < bound && i < list.Count; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边
                            for (int i = list.Count - bound; i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            // 左边中间
                            for (int i = list.Count / 3 - 3 - midbound; i < list.Count / 3 - 3 && i > 0; ++i)
                            {
                                Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl1);
                            }

                            // 右边中间
                            for (int i = list.Count * 2 / 3 + 3; i < list.Count * 2 / 3 + 3 + midbound && i < list.Count; ++i)
                            {
                                Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                                pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                                pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                                ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                                res.Add(pl2);
                            }
                            double width = list[list.Count - 1].C2D(-pointSpace, height).X - list[0].C2D(pointSpace, height).X - 2.5 * 2 * scale;
                            Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl3.AddVertexAt(0, list[0].C2D(pointSpace, height), 0, 0, 0);
                            pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl3);

                            Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, height), 0, 0, 0);
                            pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl4);

                            // 圆形标记
                            DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, height),
                                T1, Extensions.curFont, scale);
                            break;
                        }
                    default:
                        break;
                }
                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }

        public static void CreateBottomRebarPointLine(Database db, ref Extents2d ext,
 List<Point3d> list, int bottomNum, double bottomSpace, string T1, int bound, int midbound, double scale = 100, double height = 10, string layer = "H标注")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                if (list == null || list.Count <= 1)
                {
                    return;
                }
                #region 绘制
                //double height = 3.2 * scale;
                double angle = 70;
                double pointSpace = height / Math.Tan(GeTools.DegreeToRadian(angle));


                for (int i = 0; i < bound && i < list.Count; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl1.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边
                for (int i = list.Count - bound; i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl2.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl2);
                        }
                    }
                }
                // 左边中间
                for (int i = list.Count / 2 - 3 - midbound; i < list.Count / 2 - 3 && i > 0; ++i)
                {
                    Polyline pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl1.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl1);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl1 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl1.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl1.AddVertexAt(0, list[i].C2D(pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl1);
                        }
                    }
                }

                // 右边中间
                for (int i = list.Count / 2 + 3; i < list.Count / 2 + 3 + midbound && i < list.Count; ++i)
                {
                    Polyline pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                    pl2.AddVertexAt(0, list[i].C2D(), 0, 0, 0);
                    pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                    ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                    res.Add(pl2);
                    if (bottomNum > 0)
                    {
                        for (int m = 1; m < bottomNum; m++)
                        {
                            pl2 = new Polyline() { Closed = false, LayerId = lt[layer] };
                            pl2.AddVertexAt(0, list[i].C2D(0, -m * bottomSpace), 0, 0, 0);
                            pl2.AddVertexAt(0, list[i].C2D(-pointSpace, height), 0, 0, 0);
                            ext = ext.Add(new Extents2d(pl2.Bounds.Value.MinPoint.C2D(), pl2.Bounds.Value.MaxPoint.C2D()));
                            res.Add(pl2);
                        }
                    }
                }
                double width = list[list.Count - 1].C2D(-pointSpace, height).X - list[0].C2D(pointSpace, height).X - 2.5 * 2 * scale;
                Polyline pl3 = new Polyline() { Closed = false, LayerId = lt[layer] };
                pl3.AddVertexAt(0, list[0].C2D(pointSpace, height), 0, 0, 0);
                pl3.AddVertexAt(1, list[0].C2D(pointSpace + width / 2, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl3.Bounds.Value.MinPoint.C2D(), pl3.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl3);

                Polyline pl4 = new Polyline() { Closed = false, LayerId = lt[layer] };
                pl4.AddVertexAt(0, list[list.Count - 1].C2D(-pointSpace - width / 2, height), 0, 0, 0);
                pl4.AddVertexAt(1, list[list.Count - 1].C2D(-pointSpace, height), 0, 0, 0);
                ext = ext.Add(new Extents2d(pl4.Bounds.Value.MinPoint.C2D(), pl4.Bounds.Value.MaxPoint.C2D()));
                res.Add(pl4);

                // 圆形标记
                DimPloter.CircularMark(db, ref ext, list[0].C3D(pointSpace + width / 2, height),
                    T1, Extensions.curFont, scale);


                #endregion
                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }
                tr.Commit();
            }
        }


    }

    public enum eSampleType
    {
        #region 直线或标准弯钩
        UR,
        UL,
        UT,
        UB,
        UTC,
        UBC,
        UTLC,
        UBLC,
        UN,
        UC,
        #endregion
        None
        
    }
    public enum eArrowLocation
    {  
        LT,
        LB,
        RT,
        RB,
        TT,
        TB,
        BT,
        BB
    }
}
